package writable;

import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Mapper;

import java.io.IOException;

/**
 * 进行map处理，将数据以key为phone，value为FlowBean进行输出
 */
public class MapperTest extends Mapper<LongWritable, Text,Text,FlowBean> {
    @Override
    protected void map(LongWritable key, Text value, Context context) throws IOException, InterruptedException, IOException {
        String line = value.toString();
        String[] split = line.split("\t");
        FlowBean flowBean = new FlowBean();
        String phone = split[1];
        int upFlow = Integer.parseInt(split[split.length - 3]);
        int downFlow = Integer.parseInt(split[split.length - 2]);
        flowBean.setPhone(phone);
        flowBean.setUpFlow(upFlow);
        flowBean.setDownFlow(downFlow);
        /**
         * 写出到reduce中
         */
        context.write(new Text(phone),flowBean);
    }

}
